const http = require("http");
const path = require("path");
const config = require("./config/defaultConfig");
const route = require("./helper/route");

//es6的语法 类似于java lambda的写法
const server = http.createServer((req, res) => {
    //如果服务器接收到客户端的访问，这边需要做的处理
    const filePath = path.join(config.root, req.url);
    //把读取执行命令的文件夹路径封装到静态的module.exports文件中
    route(req, res, filePath);
});

//服务器监听地址和端口号
server.listen(config.port, config.hostname, () => {
    const address = `http://${config.hostname}:${config.port}`;
    console.log(`Server start at ${address}`);
});